package ooo.reindeer.springboot.starter.cedf;

import ooo.reindeer.cedf.Cedf;
import ooo.reindeer.cedf.Event;
import ooo.reindeer.cedf.IEventConsumedCallback;
import ooo.reindeer.cedf.components.IComponentsLoader;
import ooo.reindeer.cedf.components.handler.IEventHandler;
import ooo.reindeer.logging.ILogger;
import ooo.reindeer.logging.LogUtil;

public class CedfService {

    private static final ILogger logger = LogUtil.getLogger(CedfService.class);



    private void init() throws ClassNotFoundException {
        logger.info("init success");
    }

    public  boolean regEventHandler(String key, IEventHandler handler, String... types) {
        return Cedf.regEventHandler(key, handler, types);
    }

    public  boolean unRegEventHandler(String... types) {
        return Cedf.unRegEventHandler(types);
    }

    public  boolean publishEvent(String type, Object data) {
        return Cedf.publishEvent(new Event(type, data));
    }

    public  boolean publishEvent(String type, Object data, IEventConsumedCallback callback) {
        return Cedf.publishEvent(new Event(type, data), callback);
    }

    public  boolean publishEvent(Event event) {
        return Cedf.publishEvent(event);
    }

    public  boolean publishEvent(Event event, IEventConsumedCallback callback) {
        return Cedf.publishEvent(event, callback);
    }

    public <T> T handle(String type, Object data) {
        return (T)Cedf.handle(type,data);
    }

    @Deprecated
    /**
     * 废弃 setComponentsLoader 方法，将在1.0.7中删除
     */
    protected void setComponentLoader(IComponentsLoader iComponentsLoader){
        Cedf.setComponentsLoader(iComponentsLoader);
    }


    private void destroy() {
        logger.info("destroy success");
    }
}
